/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.renderer;

import com.jb.faces.component.UIComponent;
import com.jb.web.bean.FloatPanel;
import com.jb.web.context.WebContext;

/**
 * Window
 */
public class WindowRenderer extends FloatPanelRenderer {
    public StringBuffer renderBegin(WebContext pCtx, UIComponent itemToRender) {
        StringBuffer html = new StringBuffer();
        FloatPanel sect = (FloatPanel) itemToRender;
        html.append("<div ").append(addTagProperty("style", sect.getStyle(pCtx), null))
            .append(addTagProperty("class", sect.getStyleClass(), null)).append(getEditScript(pCtx, sect));

        html.append(addTagProperty("draggable", "true", null));
        html.append(addTagProperty("dragWithin", sect.getDragWithin(), null));

        if (sect.isResizable()) {
            html.append(addTagProperty("resizable", "true", null));
        }

        html.append(" >");
        html.append("<div class=\"window_header\" onmousedown=\"_selector.pick(event, '"+sect.getClientId()+"')\"");
        html.append(" >");
        html.append("<span class=\"window_title\" style=\"float:left\">"+sect.getValue()+"</span>");
        html.append("<img style=\"float:right\" src=\"resources/images/windows/window_title.gif\" onclick=\"JB.windowTitleEvent(event)\" />");
        html.append("</div>");
        html.append("<div class=\"window_content\" ");
        html.append(" >");

        return html;
    }


    public StringBuffer renderEnd(WebContext pCtx, UIComponent itemToRender) {
        return new StringBuffer("</div></div>");
    }
}
